#!/bin/bash

set -e

VOLUME_PERCENT=150  # 设定默认音量百分比

echo "[scripts]: Searching for device(usb-rockchip_4-mic_Microphone)..."

# 查找设备名
PA_DEFAULT_SOURCE_NAME=$(pactl list short sources | grep "usb-rockchip_4-mic_Microphone" | awk '{print $2}')

# 判断是否找到设备
if [ -z "$PA_DEFAULT_SOURCE_NAME" ]; then
    echo -e "\e[31m[scripts]: Error: No matching audio input device found!\e[0m"
    exit 1
fi

echo "[scripts]: Found device: $PA_DEFAULT_SOURCE_NAME"

# 设置默认音频输入设备
echo "[scripts]: Setting $PA_DEFAULT_SOURCE_NAME as the default input device..."
pactl set-default-source "$PA_DEFAULT_SOURCE_NAME"

# 设置默认音量
echo "[scripts]: Setting volume of $PA_DEFAULT_SOURCE_NAME to ${VOLUME_PERCENT}%..."
pactl set-source-volume "$PA_DEFAULT_SOURCE_NAME" "${VOLUME_PERCENT}%"

echo "[scripts]: Default input device setup completed successfully!\n"
